15 openstreetmap
Downloading OpenStreetMap data with a single line of code
Uncomment the following line to install leafmap if needed.
In [1]:
Copied!
# !pip install geopandas osmnx leafmap
# !pip install geopandas osmnx leafmap
In [2]:
Copied!
import leafmap
import leafmap
Add OSM data of place(s) by name or ID to the map. Note that the leafmap custom layer control does not support GeoJSON, we need to use the ipyleaflet built-in layer control.
In [3]:
Copied!
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_geocode("New York City", layer_name='NYC')
m
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_geocode("New York City", layer_name='NYC')
m
/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/osmnx/geocoder.py:110: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. gdf = gdf.append(_geocode_query_to_gdf(q, wr, by_osmid))
Out[3]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [4]:
Copied!
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_geocode("Chicago, Illinois", layer_name='Chicago, IL')
m
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_geocode("Chicago, Illinois", layer_name='Chicago, IL')
m
/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/osmnx/geocoder.py:110: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. gdf = gdf.append(_geocode_query_to_gdf(q, wr, by_osmid))
Out[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Add OSM entities within boundaries of geocodable place(s) to the map.
In [5]:
Copied!
m = leafmap.Map(toolbar_control=False, layers_control=True)
place = "Bunker Hill, Los Angeles, California"
tags = {"building": True}
m.add_osm_from_place(place, tags, layer_name="Los Angeles, CA")
m
m = leafmap.Map(toolbar_control=False, layers_control=True)
place = "Bunker Hill, Los Angeles, California"
tags = {"building": True}
m.add_osm_from_place(place, tags, layer_name="Los Angeles, CA")
m
/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/osmnx/geocoder.py:110: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. gdf = gdf.append(_geocode_query_to_gdf(q, wr, by_osmid))
2022-01-22 15:10:54 Configured OSMnx 1.1.2 2022-01-22 15:10:54 HTTP response caching is on 2022-01-22 15:10:54 Retrieved response from cache file "cache/8d8366ad6b96fa854a9d6d038c022b8bdcdb6fe6.json" 2022-01-22 15:10:54 Created GeoDataFrame with 1 rows from 1 queries 2022-01-22 15:10:54 Constructed place geometry polygon(s) to query API 2022-01-22 15:10:54 Projected GeoDataFrame to +proj=utm +zone=11 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +type=crs 2022-01-22 15:10:54 Projected GeoDataFrame to epsg:4326 2022-01-22 15:10:54 Requesting data within polygon from API in 1 request(s) 2022-01-22 15:10:54 Retrieved response from cache file "cache/3063abeb36c57d92b80fe38fd9a33fcf0e02c542.json" 2022-01-22 15:10:54 Got all geometries data within polygon from API in 1 request(s) 2022-01-22 15:10:54 Converting 1430 elements in JSON responses to geometries 2022-01-22 15:10:54 77 geometries created in the dict 2022-01-22 15:10:54 13 untagged geometries removed 2022-01-22 15:10:54 Created r-tree spatial index for 64 geometries 2022-01-22 15:10:54 Identified 64 geometries inside polygon 2022-01-22 15:10:54 0 geometries removed by the polygon filter 2022-01-22 15:10:54 8 geometries removed by the tag filter 2022-01-22 15:10:54 56 geometries in the final GeoDataFrame
Out[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Show OSM feature tags.
In [6]:
Copied!
# leafmap.osm_tags_list()
# leafmap.osm_tags_list()
Add OSM entities within some distance N, S, E, W of address to the map.
In [7]:
Copied!
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_address(
address="New York City",
tags={"amenity": "bar"},
dist=1500,
layer_name="NYC bars")
m
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_address(
address="New York City",
tags={"amenity": "bar"},
dist=1500,
layer_name="NYC bars")
m
2022-01-22 15:10:55 Pausing 1 seconds before making HTTP GET request 2022-01-22 15:10:56 Get https://nominatim.openstreetmap.org/search?format=json&limit=1&dedupe=0&q=New+York+City with timeout=180 2022-01-22 15:10:56 Resolved nominatim.openstreetmap.org to 140.211.167.100 2022-01-22 15:10:56 Downloaded 0.5kB from nominatim.openstreetmap.org 2022-01-22 15:10:56 Saved response to cache file "cache/78258c318356c20c380e1fed844176f90c053cf7.json" 2022-01-22 15:10:56 Geocoded "New York City" to (40.7127281, -74.0060152) 2022-01-22 15:10:56 Created bbox 1500 m from (40.7127281, -74.0060152): 40.72621790503239,40.69923829496761,-73.98821837587228,-74.02381202412771 2022-01-22 15:10:56 Projected GeoDataFrame to +proj=utm +zone=18 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +type=crs 2022-01-22 15:10:56 Projected GeoDataFrame to epsg:4326 2022-01-22 15:10:56 Requesting data within polygon from API in 1 request(s) 2022-01-22 15:10:56 Resolved overpass-api.de to 178.63.48.217 2022-01-22 15:10:56 Pausing 0 seconds before making HTTP POST request 2022-01-22 15:10:56 Post https://overpass-api.de/api/interpreter?data=%5Bout%3Ajson%5D%5Btimeout%3A180%5D%3B%28%28node%5B%27amenity%27%3D%27bar%27%5D%28poly%3A%2740.699238+-74.023812+40.699238+-73.988218+40.726218+-73.988218+40.726218+-74.023812+40.699238+-74.023812%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28way%5B%27amenity%27%3D%27bar%27%5D%28poly%3A%2740.699238+-74.023812+40.699238+-73.988218+40.726218+-73.988218+40.726218+-74.023812+40.699238+-74.023812%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28relation%5B%27amenity%27%3D%27bar%27%5D%28poly%3A%2740.699238+-74.023812+40.699238+-73.988218+40.726218+-73.988218+40.726218+-74.023812+40.699238+-74.023812%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%29%3Bout%3B with timeout=180 2022-01-22 15:10:56 Resolved overpass-api.de to 178.63.48.217 2022-01-22 15:10:59 Downloaded 37.2kB from overpass-api.de 2022-01-22 15:10:59 Saved response to cache file "cache/7d10c2e8d50f39407dda671d56290ea2808b3d4a.json" 2022-01-22 15:10:59 Got all geometries data within polygon from API in 1 request(s) 2022-01-22 15:10:59 Converting 107 elements in JSON responses to geometries 2022-01-22 15:10:59 98 geometries created in the dict 2022-01-22 15:10:59 0 untagged geometries removed 2022-01-22 15:10:59 Created r-tree spatial index for 98 geometries 2022-01-22 15:10:59 Identified 98 geometries inside polygon 2022-01-22 15:10:59 0 geometries removed by the polygon filter 2022-01-22 15:10:59 0 geometries removed by the tag filter 2022-01-22 15:10:59 98 geometries in the final GeoDataFrame
Out[7]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [8]:
Copied!
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_address(
address="New York City",
tags={
"landuse": ["retail", "commercial"],
"building": True
},
dist=1000, layer_name="NYC buildings")
m
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_address(
address="New York City",
tags={
"landuse": ["retail", "commercial"],
"building": True
},
dist=1000, layer_name="NYC buildings")
m
2022-01-22 15:10:59 Retrieved response from cache file "cache/78258c318356c20c380e1fed844176f90c053cf7.json" 2022-01-22 15:10:59 Geocoded "New York City" to (40.7127281, -74.0060152) 2022-01-22 15:10:59 Created bbox 1000 m from (40.7127281, -74.0060152): 40.721721303354926,40.703734896645074,-73.99415065058152,-74.01787974941847 2022-01-22 15:10:59 Projected GeoDataFrame to +proj=utm +zone=18 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +type=crs 2022-01-22 15:10:59 Projected GeoDataFrame to epsg:4326 2022-01-22 15:10:59 Requesting data within polygon from API in 1 request(s) 2022-01-22 15:10:59 Resolved overpass-api.de to 178.63.48.217 2022-01-22 15:11:00 Pausing 0 seconds before making HTTP POST request 2022-01-22 15:11:00 Post https://overpass-api.de/api/interpreter?data=%5Bout%3Ajson%5D%5Btimeout%3A180%5D%3B%28%28node%5B%27landuse%27%3D%27retail%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28way%5B%27landuse%27%3D%27retail%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28relation%5B%27landuse%27%3D%27retail%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28node%5B%27landuse%27%3D%27commercial%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28way%5B%27landuse%27%3D%27commercial%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28relation%5B%27landuse%27%3D%27commercial%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28node%5B%27building%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28way%5B%27building%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28relation%5B%27building%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%29%3Bout%3B with timeout=180 2022-01-22 15:11:00 Resolved overpass-api.de to 178.63.48.217 2022-01-22 15:11:10 Downloaded 2,726.6kB from overpass-api.de 2022-01-22 15:11:10 Saved response to cache file "cache/2c876f231fa35ebe028236a3fb06b51de7794ae0.json" 2022-01-22 15:11:10 Got all geometries data within polygon from API in 1 request(s) 2022-01-22 15:11:10 Converting 21003 elements in JSON responses to geometries 2022-01-22 15:11:10 2962 geometries created in the dict 2022-01-22 15:11:10 74 untagged geometries removed 2022-01-22 15:11:11 Created r-tree spatial index for 2888 geometries 2022-01-22 15:11:11 Identified 2881 geometries inside polygon 2022-01-22 15:11:11 7 geometries removed by the polygon filter 2022-01-22 15:11:11 137 geometries removed by the tag filter 2022-01-22 15:11:11 2751 geometries in the final GeoDataFrame
Out[8]:
Make this Notebook Trusted to load map: File -> Trust Notebook